package top.likeqc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import top.likeqc.common.lang.Result;
import top.likeqc.dto.CourseDTO;
import top.likeqc.entity.Course;
import top.likeqc.service.ICourseService;
import top.likeqc.service.IPointService;
import top.likeqc.service.ITeacherService;

import java.util.List;

/**
 * <p>
 * 课程表 前端控制器
 * </p>
 *
 * @author likeqc
 * @since 2022-04-10
 */
@RestController
@RequestMapping("/course")
public class CourseController extends BaseController {
    @Autowired
    ICourseService courseService;

    @Autowired
    ITeacherService teacherService;

    @Autowired
    IPointService pointService;

    @GetMapping()
    public Result list(String name) {

        // Page<Course> page = courseService.page(getPage(),
        //     new QueryWrapper<Course>().like(StringUtils.isNotBlank(key), "name", key));
        Page<Course> page = courseService.list(getPage(), name);

        return Result.success(page);
    }

    @PostMapping()
    public Result edit(@RequestBody CourseDTO course) {
        boolean b = courseService.edit(course);

        if (b) {
            return Result.success(course);
        } else {
            return Result.fail("新增、修改年级，操作失败");
        }
    }

    @DeleteMapping()
    public Result delete(@RequestBody List<Integer> ids) {

        boolean b = courseService.removeByIds(ids);
        if (b) {
            return Result.success();
        } else {
            return Result.fail("删除年级，操作失败");
        }
    }

}
